home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / StatusMonitor / UApplicationSecondStomach.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  4.9 KB  |  196 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        UApplicationSecondStomach.cp
  3.  
  4.     Contains:    *** put contents here ***
  5.  
  6.     Written by:    Steve Datnow
  7.  
  8.     Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         8/18/93    SLD    Change signature
  13.         1/7/92      SLD        Created
  14.  
  15.     To Do:
  16. */
  17.  
  18.  
  19.  
  20. #ifndef __UAPPLICATIONSecondStomach__
  21. #include "UApplicationSecondStomach.h"
  22. #endif
  23.  
  24. #ifndef __UDOCUMENTSecondStomach__
  25. #include "UDocumentSecondStomach.h"
  26. #endif
  27.  
  28. #ifndef __UViewStatusInfo__
  29. #include "UViewStatusInfo.h"
  30. #endif
  31.  
  32. #ifndef __UMENUMGR__
  33. #include "UMenuMgr.h"
  34. #endif
  35.  
  36. #ifndef __UGLOBALSSecondStomach__
  37. #include "UGlobalsSecondStomach.h"
  38. #endif
  39.  
  40. #ifndef __PPCTOOLBOX__
  41. #include "PPCToolBox.h"
  42. #endif
  43.  
  44. /****************************** Constants ******************************/
  45.  
  46. const OSType kSignature            = 'SS01';            // Application signature
  47. const long  cUpdateMonitor = 1000;
  48. const long cAreYouStillAlive = 1001;
  49.  
  50. // const CommandNumber cCommandHandledByApplication =    400;
  51.  
  52. /************************** TSSApplicaton  **********************/
  53.  
  54. //--------------------------------------------------------------------------------------------------
  55. #pragma segment AInit
  56.  
  57. pascal void TApplicationSecondStomach::IApplicationSecondStomach()
  58. {
  59.     this->IApplication(kFileType,kSignature);
  60.     fLaunchWithNewDocument = FALSE;
  61. }
  62.  
  63. //--------------------------------------------------------------------------------------------------
  64. #pragma segment AOpen
  65.             
  66. pascal TDocument* TApplicationSecondStomach::DoMakeDocument(CommandNumber /* itsCommandNumber */,
  67.                                                         TFile* itsFile) // Override 
  68. {
  69.     TDocumentSecondStomach* aDocument = new TDocumentSecondStomach;
  70.     
  71.     FailInfo fi;
  72.     if (fi.Try())
  73.     {
  74.         aDocument->IDocumentSecondStomach(itsFile,kSignature);
  75.         fi.Success();
  76.     }
  77.     else
  78.     {
  79.         aDocument = (TDocumentSecondStomach*)FreeIfObject(aDocument);
  80.         fi.ReSignal();
  81.     }
  82.     
  83.     return aDocument;
  84. }
  85.  
  86. //--------------------------------------------------------------------------------------------------
  87. #pragma segment ASelCommand
  88.  
  89. OSErr GetTargetAddress (Str255& myPrompt, Str255& myAppStr, PortInfoRec& myPortInfo, AEAddressDesc& targetAddress,TargetID& toTargetID)
  90.  
  91. {
  92.     OSErr myErr;
  93.  
  94.     myErr = PPCBrowser((ConstStr255Param) myPrompt,(ConstStr255Param) myAppStr, FALSE,toTargetID.location,myPortInfo, nil, "");
  95.  
  96.     if (myErr == noErr)
  97.     {
  98.         toTargetID.name = myPortInfo.name;
  99.         return AECreateDesc(typeTargetID,(Ptr) &toTargetID, sizeof(toTargetID), targetAddress);
  100.     }
  101.     else
  102.         return myErr;
  103. }
  104.  
  105. pascal void TApplicationSecondStomach::DoMenuCommand(CommandNumber aCommandNumber) // Override 
  106. {
  107.     switch (aCommandNumber) 
  108.     {
  109.         default:
  110.             inherited::DoMenuCommand(aCommandNumber);
  111.             break;
  112.     }
  113. }
  114.  
  115. //--------------------------------------------------------------------------------------------------
  116. #pragma segment ARes
  117.  
  118. pascal void TApplicationSecondStomach::DoSetupMenus() // Override 
  119. {
  120.     inherited::DoSetupMenus();                // Always call the inherited method first
  121.  
  122.     // Enable(cCommandHandledByApplication,TRUE);
  123. }
  124.  
  125. //--------------------------------------------------------------------------------------------------
  126.  
  127. pascal Boolean CompareSessionID(TObject* item, void* staticLink) {
  128.     TDocumentSecondStomach* theDoc = (TDocumentSecondStomach*) item;
  129.     if (theDoc->GetSessionID() == (long) staticLink)
  130.         return TRUE;
  131.     else
  132.         return FALSE;
  133. }
  134.  
  135. pascal void TApplicationSecondStomach::DoAppleCommand(CommandNumber aCommandNumber,
  136.                                          const AppleEvent& message,
  137.                                          const AppleEvent& reply)
  138. {
  139.     TAppleEvent* theMessage;
  140.     TAppleEvent* theReply;
  141.     long sessionID;
  142.     TDocumentSecondStomach * myDoc;
  143.             
  144.     switch (aCommandNumber)
  145.     {
  146.         case cUpdateMonitor:
  147.             {
  148.                 FailInfo fi;
  149.                 if (fi.Try())
  150.                 {
  151.                     theMessage = new TAppleEvent;
  152.                     theMessage->InitializeFromMessage(message, FALSE);
  153.                     
  154.                     sessionID = theMessage->ReadLong('SSID');                // Which document is it destined for ?
  155.                     if (fDocumentList)
  156.                         myDoc = (TDocumentSecondStomach *) fDocumentList->FirstThat(&CompareSessionID, (void*) sessionID);
  157.                     
  158.                     if (myDoc)
  159.                         myDoc->HandleStatusInfo(theMessage);
  160.                         
  161.                     theMessage = (TAppleEvent *)FreeIfObject(theMessage);                    
  162.                     fi.Success();
  163.                 }
  164.                 else    // Recover
  165.                 {
  166.                     theMessage = (TAppleEvent *)FreeIfObject(theMessage);
  167.                     fi.ReSignal();
  168.                 }
  169.             }
  170.             break;
  171.         case cAreYouStillAlive:
  172.             {
  173.                 theMessage = new TAppleEvent;
  174.                 theMessage->InitializeFromMessage(message, FALSE);
  175.                 theReply = new TAppleEvent;
  176.                 theReply->InitializeFromMessage(reply, FALSE);
  177.                 sessionID = theMessage->ReadLong('SSID');
  178.                 if (fDocumentList)
  179.                         myDoc = (TDocumentSecondStomach *) fDocumentList->FirstThat(&CompareSessionID, (void*) sessionID);
  180.                     
  181.                 if (myDoc == nil)
  182.                     sessionID = -1;
  183.                 
  184.                  theReply->WriteLong('SSID',sessionID);
  185.                 theReply->Send();
  186.                 
  187.                 theMessage = (TAppleEvent *)FreeIfObject(theMessage);    
  188.                 theReply = (TAppleEvent *)FreeIfObject(theReply);        
  189.             }
  190.             break;
  191.         default:
  192.             inherited::DoAppleCommand(aCommandNumber, message, reply);
  193.             break;
  194.     }
  195. }
  196.